// HexEdit.cpp : implementation file
//

#include "stdafx.h"
#include "HexEdit.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CHexEdit

BOOL g_bHex = TRUE;

CHexEdit::CHexEdit()
{
}

CHexEdit::~CHexEdit()
{
}


BEGIN_MESSAGE_MAP(CHexEdit, CEdit)
	//{{AFX_MSG_MAP(CHexEdit)
	ON_WM_CHAR()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CHexEdit message handlers

void CHexEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
	// TODO: Add your message handler code here and/or call default
	if ( g_bHex )
	{
		if ( _T( 'a' ) <= nChar && nChar <= _T( 'f' ) )
		{
			nChar -= _T( 'a' ) - _T( 'A' );
		}

		if (( _T( '0' ) <= nChar && nChar <= _T( '9' )) || ( _T( 'A' ) <= nChar && nChar <= _T( 'F' ))
			|| VK_BACK == nChar || VK_DELETE == nChar || 0 > GetKeyState( VK_CONTROL ))
		{
			CEdit::OnChar(nChar, nRepCnt, nFlags);
		}
	}
	else
	{
		if (( _T( '0' ) <= nChar && nChar <= _T( '9' ))
			|| VK_BACK == nChar || VK_DELETE == nChar || 0 > GetKeyState( VK_CONTROL ))
		{
			CEdit::OnChar(nChar, nRepCnt, nFlags);
		}
	}
}
